<?php

    class itSimpleRulesTest extends itTestCase {
        
        /**
         * @test
         */
        public function testBasePath() {
            $s = new itSimpleRules();
            $s->setPrefix('A');
            $this->assertEquals('A', $s->getPrefix());
        }
        
        
        /**
         * @test
         */
        public function testAddFiles() {
            $s = new itSimpleRules();
            $s->addFile('File1');
            $s->addFile('File2');
            $this->assertEquals(array('File1', 'File2'), $s->toPersistentCache());
            $s->addFiles(array('File3'));
            $this->assertEquals(array('File1', 'File2', 'File3'), $s->toPersistentCache());
        }

        /**
         * @test
         */
        public function testArrayFromCache() {
            $s = new itSimpleRules();
            $s->fromPersistentCache(array('File1'));
            $this->assertEquals(array('File1'), $s->toPersistentCache());
        }
        
        public function testToClassRules() {
            $file1 = TEST_DATA.'/Individual/Rules/Simple/ClassesNoNS.php';
            $s = new itSimpleRules();
            $s->addFile($file1);
            $classRules = $s->toClassRules(new itScanner());
            $this->assertTrue($classRules->hasClass('ClassNoNSSimpleRules'));
            $this->assertTrue($classRules->hasClass('InterfaceNoNSSimpleRules'));
        }
        
        /**
         * @test
         */
        public function testToClassRulesNS() {
            if ($this->cmpCurrentPHPVersion('5.3.0') < 0) {
                return;
            }
            $file1 = TEST_DATA.'/Individual/Rules/Simple/Classes1.php';
            $file2 = TEST_DATA.'/Individual/Rules/Simple/Classes2.php';
            $s = new itSimpleRules();
            $s->addFile($file1);
            $s->addFile($file2);
            $classRules = $s->toClassRules(new itScanner());
            $this->assertTrue($classRules->hasClass('Namespace1\Sub\Class1'));
            $this->assertTrue($classRules->hasClass('Namespace1\Sub\Class2'));
            $this->assertTrue($classRules->hasClass('Namespace1\Sub\Interface1'));
            $this->assertTrue($classRules->hasClass('Namespace1\Sub\Sub2\Class1'));
            $this->assertTrue($classRules->hasClass('A\A'));
            $this->assertTrue($classRules->hasClass('A\B'));
        }
    }
    
?>